/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.mrp.ppm.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import merlion.scm.rmpm.entity.RawMaterial;

/**
 *
 * @author Zhu Xin
 */
@Entity
public class BOM implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    @OneToOne(targetEntity = RawMaterial.class, cascade = {CascadeType.MERGE}, fetch = FetchType.EAGER)
    private RawMaterial material;
    
    @OrderBy("index")
    //@OneToMany(targetEntity=IndexNValue.class, cascade={CascadeType.ALL}, fetch= FetchType.EAGER)
    private List<IndexNDouble> materialRequirements = new ArrayList<IndexNDouble>();  //size 4

    public BOM() {
        for (int i = 0; i < 4; i++) {
            materialRequirements.add(new IndexNDouble(i, 0.0));
        }
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public RawMaterial getMaterial() {
        return material;
    }

    public void setMaterial(RawMaterial material) {
        this.material = material;
    }

    public List<IndexNDouble> getMaterialRequirements() {
        return materialRequirements;
    }

    public void setMaterialRequirements(List<IndexNDouble> materialRequirements) {
        this.materialRequirements = materialRequirements;
    }

    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof BOM)) {
            return false;
        }
        BOM other = (BOM) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.mrp.ppm.entity.BOM[ id=" + id + " ]";
    }
    
}
